package com.bignerdranch.android.ecar.Adapter;

import android.content.Context;
import android.graphics.Paint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bignerdranch.android.ecar.Bean.MaintainBean;
import com.bignerdranch.android.ecar.R;

import java.util.List;


/**
 * Created by Administrator on 2016/7/25.
 */
public class MaintainAdapter extends BaseAdapter {

    private Context mContext;
    private LayoutInflater mInflater;
    private List<MaintainBean> mData;

    public MaintainAdapter(Context context, List<MaintainBean> data) {
        mContext = context;
        mData = data;
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public Object getItem(int position) {
        return mData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView==null){
            convertView= mInflater.inflate(R.layout.maintain_item,null);
        }
        ViewHold hold = new ViewHold();
        if (convertView.getTag()==null){
            hold.imgRes = (ImageView) convertView.findViewById(R.id.imgRes);
            hold.meal = (TextView) convertView.findViewById(R.id.meal);
            hold.location = (TextView) convertView.findViewById(R.id.location);
            hold.price_now = (TextView) convertView.findViewById(R.id.price_now);
            hold.price_old = (TextView) convertView.findViewById(R.id.price_old);
            hold.people_num = (TextView) convertView.findViewById(R.id.people_num);


            convertView.setTag(hold);
        }else {
            hold = (ViewHold) convertView.getTag();
        }

        hold.imgRes.setImageResource(mData.get(position).getImgRes());
        hold.meal.setText(mData.get(position).getMeal());
        hold.location.setText(mData.get(position).getLocation());
        hold.price_now.setText(mData.get(position).getPrice_now());
        hold.price_old.setText(mData.get(position).getPrice_old());
        hold.price_old.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
        hold.people_num.setText(mData.get(position).getPeople_num());

        return convertView;
    }

    private static class ViewHold{
        private ImageView imgRes;
        private TextView meal;
        private TextView location;
        private TextView price_now;
        private TextView price_old;
        private TextView people_num;
    }
}
